import java.io.DataInput; 
import java.io.DataOutput; 
import java.io.IOException; 
import java.text.ParseException; 
import java.text.SimpleDateFormat; 
import java.util.Date; 
  
import org.apache.hadoop.io.WritableComparable; 
  
class DateWritableComparable implements WritableComparable<DateWritableComparable> { 
      protected Date date; 
         
      public DateWritableComparable() {  
          date = null; 
      } 
       
      public DateWritableComparable(String s) throws ParseException { 
          date = new SimpleDateFormat().parse(s);  
      } 
       
    @Override 
      public void write(DataOutput out) throws IOException { 
          out.writeLong(date.getTime()); 
      } 
  
    @Override 
      public void readFields(DataInput in) throws IOException { 
        date = new Date(in.readLong()); 
      } 
  
    @Override 
    public int compareTo(DateWritableComparable other) { 
        return date.compareTo(other.date); 
    } 
     
}
